package com.hzit.security.handler;

import com.alibaba.fastjson.JSON;
import com.hzit.util.R;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 类名：
 * 作者：WF
 * 功能：授权失败的逻辑处理器
 */
@Component
public class HzitAuthenticationFailureHandler implements AuthenticationFailureHandler {
	@Override
	public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
		response.setContentType("text/html;charset=utf8");
		R<Object> fail = R.fail("认证出错了！");
		String s = JSON.toJSONString(fail);
		response.getWriter().println(s);
		response.getWriter().flush();
	}
}
